/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package towerz.component;

import java.io.IOException;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import towerz.system.BitmapFont;
import towerz.system.Utilities;

/**
 *
 * @author TimotiusNC
 */
public class ButtonPush extends Button {
	protected  ButtonPush() {
		//Initialize
		m_Push		= true;
		m_Alignment = Graphics.LEFT | Graphics.TOP;
		
		//Create if pointer is null
		if (s_Pointer == null) {
			try {
				s_Pointer = Image.createImage(Utilities.INTERFACE_FOLDER + "/selection1.png");
			} catch (IOException ex) {}
		}
	}

	public ButtonPush(int id, String imgPath, int x, int y){
		//Default
		this();
		
		m_ID	= id;
		m_X		= x;
		m_Y		= y;

		setImage(imgPath);
	}

	public ButtonPush(String buttonTitle, int id, int x, int y){
		//Default
		this();
		
		m_ID	= id;
		m_X		= x;
		m_Y		= y;

		//Set image
		m_Img = BitmapFont.getFont(BitmapFont.TITLE).renderTransparentText(buttonTitle, 0x00000000);
	}
	
	public int getWidth() {
		return m_Img.getWidth();
	}
	
	public int getHeight() {
		return m_Img.getHeight();
	}

	public void setText(String text){
		m_Img = BitmapFont.getFont(BitmapFont.TITLE).renderTransparentText(text, 0x00000000);
	}
	
	public void setAlignment(int align) {
		m_Alignment = align;
	}
	
	public void setPush(boolean push) {
		m_Push = push;
	}

	public final void setImage(String imgPath){
		try {
			m_Img = Image.createImage(imgPath);
		} catch (IOException ex) {}
	}

	public void draw(Graphics g) {
		//Draw based on the state
		boolean NotSelected = !m_Push || m_State == Button.STATE_NONE;
		g.drawImage(m_Img, m_X + (NotSelected ? 0 : s_Pointer.getWidth() + 4), m_Y, m_Alignment);
		if (!NotSelected) g.drawImage(s_Pointer, m_X, m_Y + 1, Graphics.LEFT | Graphics.TOP);
	}

	//DISPLAY
	protected Image		m_Img;
	protected int		m_Alignment;
	protected boolean	m_Push;
	
	protected static Image s_Pointer = null;
}
